<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Guru_model extends CI_Model {

	function __construct()
	{
		parent::__construct();
		$this->CI = get_instance();
	}
	
	function insert_guru($data){
		$query = $this->db->insert('tb_pegawai',$data);
		return $query;
	}
	
	function get_guru(){
		
		$this->db->select('p.*,s.STATUS as NAMA_STATUS');
		$this->db->from('tb_pegawai p'); 
		$this->db->join('tb_master_status s','s.ID_STATUS=p.STATUS'); 
		$this->db->where('p.IS_AKADEMIK', 1); //1 = guru, 0 = pegawai
		$this->db->where('ISAKTIF', 1); 
		$this->CI->flexigrid->build_query();
		
		$return['records'] = $this->db->get();
		
		$this->db->select('p.*,s.STATUS as NAMA_STATUS');
		$this->db->from('tb_pegawai p');
		$this->db->join('tb_master_status s','s.ID_STATUS=p.STATUS'); 
		$this->db->where('p.IS_AKADEMIK', 1); //1 = guru, 0 = pegawai
		$this->db->where('ISAKTIF', 1);
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();

		return $return;
	}
	
	function get_pegawai(){
		
		$this->db->select('p.*,s.STATUS as NAMA_STATUS');
		$this->db->from('tb_pegawai p'); 
		$this->db->join('tb_master_status s','s.ID_STATUS=p.STATUS');
		$this->db->where('p.IS_AKADEMIK', 0); //1 = guru, 0 = pegawai	
		$this->db->where('ISAKTIF', 1); 		
		$this->CI->flexigrid->build_query();
		
		$return['records'] = $this->db->get();
		
		$this->db->select('p.*,s.STATUS as NAMA_STATUS');
		$this->db->from('tb_pegawai p');
		$this->db->join('tb_master_status s','s.ID_STATUS=p.STATUS'); 
		$this->db->where('p.IS_AKADEMIK', 0); //1 = guru, 0 = pegawai
		$this->db->where('ISAKTIF', 1); 
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();

		return $return;
	}
	
	function get_pegawai_laporan(){
		
		$this->db->select('p.*,s.STATUS as NAMA_STATUS');
		$this->db->from('tb_pegawai p'); 
		$this->db->join('tb_master_status s','s.ID_STATUS=p.STATUS');
		$this->db->where('p.IS_AKADEMIK', 0); //1 = guru, 0 = pegawai	
		$this->db->where('ISAKTIF', 1); 
		$query = $this->db->get();
		return $query;
	}
	
	function get_guru_laporan(){
		
		$this->db->select('p.*,s.STATUS as NAMA_STATUS');
		$this->db->from('tb_pegawai p'); 
		$this->db->join('tb_master_status s','s.ID_STATUS=p.STATUS');
		$this->db->where('p.IS_AKADEMIK', 1); //1 = guru, 0 = pegawai	
		$this->db->where('ISAKTIF', 1); 
		$query = $this->db->get();
		return $query;
	}
	
	function delete_guru($nip){
		$this->db->where('NIP', $nip);
		$this->db->delete('tb_pegawai'); 
	}
	
	function get_guruID($nip){
		
		//Select table column
		$this->db->select('p.*, s.ID_STATUS as ID_STATUS, a.NAMA_AGAMA');
		$this->db->from('tb_pegawai p');
		$this->db->join('tb_master_status s','s.ID_STATUS=p.STATUS'); 
		$this->db->join('tb_master_agama a','a.ID_AGAMA=p.AGAMA'); 
		$this->db->where('NIP',$nip);
		$query = $this->db->get();
		return $query;
	}
	
	function update_guru($data,$nip){
		$this->db->where('NIP',$nip);
		$this->db->update('tb_pegawai',$data);
	}
	
	//=============================================================
	function combo_agama(){
		$this->db->select('*');
		$this->db->from('tb_master_agama');
		$query = $this->db->get();
		return $query;
	}
	
	function combo_status($jenis=''){
		$this->db->select('*');
		$this->db->from('tb_master_status');
		if($jenis=='pegawai')
			$this->db->where('IS_AKADEMIK',0);
		else
			$this->db->where('IS_AKADEMIK',1);
		$query = $this->db->get();
		return $query;
	}
	
	function get_pegawai_guru($akademik){
		
		$this->db->select('p.*');
		$this->db->from('tb_pegawai p'); 
		$this->db->where('ISAKTIF', 1); 
		if($akademik!='')
			$this->db->where('IS_AKADEMIK', $akademik); 
		$this->CI->flexigrid->build_query();
		
		$return['records'] = $this->db->get();
		
		$this->db->select('p.*');
		$this->db->from('tb_pegawai p');
		$this->db->where('ISAKTIF', 1); 
		if($akademik!='')
			$this->db->where('IS_AKADEMIK', $akademik); 
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();

		return $return;
	}
	
	function get_idguru($nip){
		//Select table column
		$this->db->select('count(*) AS JUMLAH');
		$this->db->from('tb_pegawai');
		$this->db->where('NIP',$nip);
		$query = $this->db->get()->row()->JUMLAH;
		
		return $query;
	}
	
}

?>
